<?php
/**
 * Yotaku shop - yshop
 * Copyright (c) 2016 http://www.yotaku.cn All rights reserved.
 * Author: Creatint <creatint@163.com> <http://creatint.yotaku.cn>
 */
namespace Admin\Model;
use Think\Model;
class ConfigModel extends Model{
    protected $error    =   null;
    public function getConfig(){
        $map = array();
        $res = $this->where($map)->select();
        return $res;
    }
    public function getDetail($id){
        $map = array();
        $map['id'] = $id;
        $res = $this->where($map)->find();
        return $res;
    }

    public function update($data=null){
        if(!$data){
            $this->error = '数据为空';
            return false;
        }
        $data = $this->create($data);
        if($data['id']){
            $this->where("id={$data['id']}")->save($data);
        }else{
            $id = $this->add();
            if(!$id){
                $this->error = '新增失败';
                return false;
            }
        }
        return $data;
    }
    public function getError(){
        return $this->error;
    }
    public function del($id){
        if(empty($id)){
            $this->error = '请选择要删除的配置项';
        }
        $map = array('id'=>array('IN',trim(implode(',',$id),',')));
        //$res = $this->where($map)->delete();
        if($this->where($map)->delete()){
            S('DB_CONFIG',null);
            return true;
        }else{
            $this->error = '无此条数据';
            return false;
        }
    }
}